//
//  ProfessionTableViewCell.m
//  GiftSay
//
//  Created by laohu on 16/1/7.
//  Copyright © 2016年 liyinkai. All rights reserved.
//

#import "ProfessionTableViewCell.h"
#import "HXTactikFirstModel.h"
@implementation ProfessionTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        [self createView];
        
        
    }
    return self;
}



- (void)layoutSubviews {
    [super layoutSubviews];
    self.label.frame = CGRectMake(0, 0, self.width, 35);
    
    self.button.frame = CGRectMake(0.7 *self.width, 0.4 * self.label.height, 0.3 * self.width, 0.28 * self.label.height);
    
    self.scrollView.frame = CGRectMake(0, self.label.bottom, self.width, self.height - self.label.bottom - 5);
    [self.scrollView setContentSize:CGSizeMake((self.width / 2 - 20) * self.dataSource.count + 20, 0)];

    for (int i = 0; i < self.dataSource.count; i++) {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 20 * i + (self.width / 2 - 40) * i , self.scrollView.top - 45, self.width / 2 - 40, (self.width / 2 - 40) / 2)];
        image.backgroundColor = [UIColor redColor];
//        image.layer.cornerRadius = 2;
        HXTactikFirstModel *first = self.dataSource[i];
        NSString *str = first.banner_image_url;
        [image setImageWithURL:[NSURL URLWithString:str] placeholder:nil];
        [self.scrollView addSubview:image];
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.tag = 1000 + i;
        button.frame = image.frame;
        button.backgroundColor = [UIColor whiteColor];
        button.alpha = 0.1;
        [button addTarget:self action:@selector(buttonDidPress:) forControlEvents:UIControlEventTouchUpInside];
        [self.scrollView addSubview:button];
        
    }
    
    

}

- (void)buttonDidPress:(UIButton *)sender {
//    NSLog(@"asdsad");
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"scrollJumpToDetail" object:self.dataSource[sender.tag - 1000] ];
    
}



- (void)createView {
    self.label = [[UILabel alloc] initWithFrame:CGRectZero];
//    self.label.backgroundColor = [UIColor redColor];
    self.label.font = [UIFont systemFontOfSize:17 * SCREEN_WIDTH];
    [self addSubview:_label];
    self.label.text = @"专题";
    self.label.textAlignment = NSTextAlignmentLeft;
    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    self.button.frame = CGRectZero;
    [self.button setTitle:@"查看全部专题" forState:UIControlStateNormal];
    [self.button setTitleColor:[UIColor colorWithRed:75 / 255.0 green:75 / 255.0 blue:75 / 255.0 alpha:1] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(allButtonDidPress:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_button];
    
    
    
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
    self.scrollView.backgroundColor = [UIColor whiteColor];
//    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.bounces = YES;
    [self addSubview:_scrollView];
    
    
}

- (void)allButtonDidPress:(UIButton *)sender {
//    NSLog(@"全部专题");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"AllProfession" object:nil];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
